Change in openvpn[master]: dco-win: multipeer support
A message that is not in the archive (sent off-list or not yet received): gerrit.1732212459000.Ia267276d61fa1425ba205f54ba6eb89021f32dba@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
to review the following change.
Change subject: dco-win: multipeer support
......................................................................
dco-win: multipeer support
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depends on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/ovpn_dco_win.h
M src/openvpn/socket.c
M src/openvpn/socket.h
10 files changed, 518 insertions(+), 103 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/15/815/1
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -284,7 +285,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -391,7 +391,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +278 -38
428 lines not on this page · raw message
src/openvpn/dco_win.h +13 -4
@@ -31,19 +31,28 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { + dco_mode_uninit, + dco_mode_p2p, + dco_mode_mp +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type mode; + };typedef struct dco_context dco_context_t ;struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +create_dco_handle (const char *devname,struct gc_arena *gc,int mode);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock); + +void +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +2 -1
@@ -1315,7 +1315,8 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +bool prepend_sa = c->options.mode ==MODE_SERVER &&dco_enabled (&c->options); +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = prepend_sa };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -1987,7 +1987,7 @@#endif if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +90 -3
115 lines not on this page · raw message
src/openvpn/socket.c +108 -52
194 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1042,6 +1044,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1112,6 +1115,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: plaisthos, stipa.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 1:
(2 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/1ce19e92_b7d332b3 :
PS1, Line 13: which is peer-to-peer or multipeer. Depends on mode, "Depending"
http://gerrit.openvpn.net/c/openvpn/+/815/comment/7ac9dcb0_dc2d3e45 :
PS1, Line 25: guesswork figure out IP address based on remote IP and local "to figure out"
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 22 Nov 2024 14:59:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 2:
(2 comments)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/feb95366_18bad37b :
PS1, Line 13: which is peer-to-peer or multipeer. Depends on mode,
Quoted 1 line
"Depending"
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/815/comment/a36d4478_9d54a2df :
PS1, Line 25: guesswork figure out IP address based on remote IP and local
Quoted 1 line
"to figure out"
Acknowledged
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 22 Nov 2024 15:37:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
to look at the new patch set (#3).
Change subject: dco-win: multipeer support
......................................................................
dco-win: multipeer support
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depending on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork to figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/ovpn_dco_win.h
M src/openvpn/socket.c
M src/openvpn/socket.h
10 files changed, 518 insertions(+), 103 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/15/815/3
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -284,7 +285,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -391,7 +391,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +278 -38
428 lines not on this page · raw message
src/openvpn/dco_win.h +13 -4
@@ -31,19 +31,28 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { + dco_mode_uninit, + dco_mode_p2p, + dco_mode_mp +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type mode; + };typedef struct dco_context dco_context_t ;struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +create_dco_handle (const char *devname,struct gc_arena *gc,int mode);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock); + +void +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +2 -1
@@ -1315,7 +1315,8 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +bool prepend_sa = c->options.mode ==MODE_SERVER &&dco_enabled (&c->options); +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = prepend_sa };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -1987,7 +1987,7 @@#endif if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +90 -3
115 lines not on this page · raw message
src/openvpn/socket.c +108 -52
194 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1042,6 +1044,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1112,6 +1115,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
to look at the new patch set (#12).
Change subject: dco-win: multipeer support
......................................................................
dco-win: multipeer support
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depending on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork to figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/ovpn_dco_win.h
M src/openvpn/socket.c
M src/openvpn/socket.h
10 files changed, 518 insertions(+), 103 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/15/815/12
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -284,7 +285,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -391,7 +391,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +278 -38
428 lines not on this page · raw message
src/openvpn/dco_win.h +13 -4
@@ -31,19 +31,28 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { + dco_mode_uninit, + dco_mode_p2p, + dco_mode_mp +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type mode; + };typedef struct dco_context dco_context_t ;struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +create_dco_handle (const char *devname,struct gc_arena *gc,int mode);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock); + +void +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +2 -1
@@ -1323,7 +1323,8 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +bool prepend_sa = c->options.mode ==MODE_SERVER &&dco_enabled (&c->options); +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = prepend_sa };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -2005,7 +2005,7 @@if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +90 -3
115 lines not on this page · raw message
src/openvpn/socket.c +108 -52
194 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1046,6 +1048,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1116,6 +1119,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 12
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 14: Code-Review+1
(1 comment)
Patchset:
PS14:
This looks all reasonable from what I have seen. It needs to be rebased to the current state of "multisocket" (just use today's master) because too much has changed in the "local socket" handling - mostly "everything is an array now".
I would suggest to have an extra check if (number of --local statements > 1) { disable_dco(); } and then just use link_socket[0] - as long as the kernel driver doesn't support multi sockets, we do not need to bother with that in the userland side (and multisocket isn't done yet anyway).
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 14
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 04 Feb 2025 20:11:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 18: Code-Review-1
(13 comments)
Patchset:
PS18:
Oh well, when I start, I tend to find things... sorry for that.
File src/openvpn/dco_win.h:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/8bc501cb_073ac40b :
PS18, Line 42: dco_mode_type mode;
I'm not really happy with that. dco_linux has its own very similar enum, with uppercase DCO_MODE_<xx> and calls the member variable dco->ifmode. Since it does the same thing, can you name the windows variant ifmode as well, and also use uppercase for the enum? (re-using the enum is not trivial because it comes from ovpn_dco_linux.h but won't be necessary, I think, as long as it's clear "it does the same thing").
Maybe ovpn_dco_init() can also be modeled to be more lookalike?
File src/openvpn/dco_win.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/9f12680a_836a673a :
PS18, Line 127:
A few words of comment somewhere on the call chain "who calls what, in which sequence" for p2p and mp mode would help me get less confused... there's so many "open", "init" and "start" functions here.
http://gerrit.openvpn.net/c/openvpn/+/815/comment/410773f9_bc0b637c :
PS18, Line 132: dco->mode = (mode == MODE_POINT_TO_POINT) ? dco_mode_p2p : dco_mode_mp;
that comment is slightly confusing - if it is "already set", then why do we set it again?
http://gerrit.openvpn.net/c/openvpn/+/815/comment/f14e44de_56a2dc7b :
PS18, Line 146: OVPN_MODE m = OVPN_MODE_MP;
here we have a new define for communication between driver and userland, which does the same as dco_mode_mp...
http://gerrit.openvpn.net/c/openvpn/+/815/comment/aaa33b91_1d10db5c :
PS18, Line 291: if (out.ListenAddress.Addr4.sin_family == AF_INET)
This part confuses me. What is out? Why is it put into actual.dest? This seems to be the address of the peer we're talking to, judging from other uses of actual.dest but then it shouldn't be tied to the "global" DCO opening, but to individual peers? Or am I totally misunderstanding this?
http://gerrit.openvpn.net/c/openvpn/+/815/comment/ac5dc11e_4884b3b4 :
PS18, Line 393: {
I do wonder why this is necessary. "Use best source for destination" is what happens automatically when passing an UDP packet without source to sendto(). Is this different in kernel space? Why was this not needed for p2p win-dco?
(As in, if kernel space will automatically put the "best source" in the packet anyway, we can just get rid of all code dealing with "best_src")
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/c2131d8c_f342751d :
PS18, Line 1326: bool prepend_sa = c->options.mode == MODE_SERVER && dco_enabled(&c->options);
we do have SF_PREPEND_SA set on the sockflags - is that available here?
File src/openvpn/ovpn_dco_win.h:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/bd9f5732_254ace41 :
PS18, Line 120: } OVPN_CRYPTO_DATA_V2, * POVPN_CRYPTO_DATA_V2;
these two are not part of *this* patch set, and might need revisiting for "the new epoch thing"
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/141b9fd2_5cf1aa60 :
PS18, Line 2256: else
since there is a "goto done" in the if() we could get rid of the else and the dangling brackets outside of the #endif...
http://gerrit.openvpn.net/c/openvpn/+/815/comment/0df307dd_57fedb84 :
PS18, Line 3857: sa_len = sizeof(struct sockaddr_in);
the repetition of sizeof(struct sockaddr_in) makes my eyes hurt... what about assigning sa_len first and then doing if (buf_len() < sa_len)... memcpy(...sa_len) etc?
http://gerrit.openvpn.net/c/openvpn/+/815/comment/f9087006_6ac2ed8b :
PS18, Line 3867: sa_len = sizeof(struct sockaddr_in6);
same here
http://gerrit.openvpn.net/c/openvpn/+/815/comment/445a211f_710bf77b :
PS18, Line 3957: read_sockaddr_from_overlapped(io, &from->dest.addr.sa, ret);
I do not understand these two sh.is_handle cases. Isn't this always a handle on windows? Or is this the "regular socket" case, and only wintun + dco have is_handle?
Also, the conditon on if (from) is interesting, so if from happens to be NULL, we wouldn't read_sockaddr_from_packet() and subsequently the packet will be malformed... can it ever be NULL here?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 18
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Wed, 05 Feb 2025 19:11:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
to look at the new patch set (#19).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: dco-win: multipeer support
......................................................................
dco-win: multipeer support
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depending on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork to figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/ovpn_dco_win.h
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.c
11 files changed, 477 insertions(+), 132 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/15/815/19
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -284,7 +285,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -422,7 +422,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +240 -61
395 lines not on this page · raw message
src/openvpn/dco_win.h +11 -5
@@ -31,19 +31,25 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { +DCO_MODE_UNINIT , +DCO_MODE_P2P , +DCO_MODE_MP +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type ifmode; + };typedef struct dco_context dco_context_t ; -struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +void +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +4 -1
@@ -1323,7 +1323,10 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +/* we cannot end up here when using dco */ +ASSERT (!dco_enabled (&c->options)); + +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = false };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -2005,7 +2005,7 @@if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +82 -3
107 lines not on this page · raw message
src/openvpn/socket.c +112 -56
203 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1046,6 +1048,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1116,6 +1119,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
src/openvpn/tun.c +1 -1
@@ -992,7 +992,7 @@#ifdef _WIN32if (tt->backend_driver ==DRIVER_DCO ) { -dco_start_tun (tt); + tt->dco.tt = tt;return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 19
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 19:
(12 comments)
File src/openvpn/dco_win.h:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/4fc86de9_75204ca5 :
PS18, Line 42: dco_mode_type mode;
Quoted 1 line
I'm not really happy with that. […]
Acknowledged
File src/openvpn/dco_win.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/958d5b8c_a18c12a8 :
PS18, Line 127:
Quoted 1 line
A few words of comment somewhere on the call chain "who calls what, in which sequence" for p2p and m […]
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/815/comment/23adf9fa_be8de950 :
PS18, Line 132: dco->mode = (mode == MODE_POINT_TO_POINT) ? dco_mode_p2p : dco_mode_mp;
Quoted 1 line
that comment is slightly confusing - if it is "already set", then why do we set it again?
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/815/comment/7778dea2_f293c54f :
PS18, Line 146: OVPN_MODE m = OVPN_MODE_MP;
Quoted 1 line
here we have a new define for communication between driver and userland, which does the same as `dco […]
Yeah, this one is from the driver API. But I see the frustration.
http://gerrit.openvpn.net/c/openvpn/+/815/comment/0dc53053_22601180 :
PS18, Line 291: if (out.ListenAddress.Addr4.sin_family == AF_INET)
Quoted 1 line
This part confuses me. What is
out? Why is it put into `actual. […]
The driver writes to out the local transport address of the socket after the bind() call. But we already know the local bind address, except maybe the port, we probably don't want to bind to port 0. It seems that there is no use of this data, so I'll remove those lines.
http://gerrit.openvpn.net/c/openvpn/+/815/comment/26e4fbd9_488525de :
PS18, Line 393: {
Quoted 1 line
I do wonder why this is necessary. […]
I see. At the moment driver doesn't use local transport address of the peer, although this is a part of API. I will remove this code.
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/ea8ee09a_b0ad999b :
PS18, Line 1326: bool prepend_sa = c->options.mode == MODE_SERVER && dco_enabled(&c->options);
Quoted 1 line
we do have
SF_PREPEND_SAset on the sockflags - is that available here?
Actually we cannot end up here when using DCO. So prepend_sa should be false and I will add an ASSERT(!dco_enabled(&c->options));
File src/openvpn/ovpn_dco_win.h:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/98441252_eacace58 :
PS18, Line 120: } OVPN_CRYPTO_DATA_V2, * POVPN_CRYPTO_DATA_V2;
Quoted 1 line
these two are not part of *this* patch set, and might need revisiting for "the new epoch thing"
Acknowledged
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/9f6896eb_6e2a0bdf :
PS18, Line 2256: else
Quoted 1 line
since there is a "goto done" in the
if()we could get rid of theelseand the dangling brackets […]
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/815/comment/be0ef538_110ecee4 :
PS18, Line 3857: sa_len = sizeof(struct sockaddr_in);
Quoted 1 line
the repetition of
sizeof(struct sockaddr_in)makes my eyes hurt... […]
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/815/comment/c8f0d980_977d5293 :
PS18, Line 3867: sa_len = sizeof(struct sockaddr_in6);
Quoted 1 line
same here
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/815/comment/69e4d1f0_887d9531 :
PS18, Line 3957: read_sockaddr_from_overlapped(io, &from->dest.addr.sa, ret);
Quoted 1 line
I do not understand these two
sh.is_handlecases. […]
SH could be either file descriptor (in case of non-dco link) or handle (non-dco tun and dco link).
from is NULL in case of non-dco tun and read tcp link - but my patch hasn't changed that.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 19
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 06 Feb 2025 18:45:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 19:
(5 comments)
File src/openvpn/dco_win.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/00d94363_34c9a1fd :
PS18, Line 146: OVPN_MODE m = OVPN_MODE_MP;
Quoted 1 line
Yeah, this one is from the driver API. But I see the frustration.
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/815/comment/33928f1a_ab08b8c6 :
PS18, Line 291: if (out.ListenAddress.Addr4.sin_family == AF_INET)
Quoted 1 line
The driver writes to out the local transport address of the socket after the
bind()call. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/815/comment/f8813ec3_9bac21f1 :
PS18, Line 393: {
Quoted 1 line
I see. […]
Done
File src/openvpn/forward.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/825741c8_e6fea2d1 :
PS18, Line 1326: bool prepend_sa = c->options.mode == MODE_SERVER && dco_enabled(&c->options);
Quoted 1 line
Actually we cannot end up here when using DCO. […]
Done
File src/openvpn/socket.c:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/c67d8e5e_442ec891 :
PS18, Line 3957: read_sockaddr_from_overlapped(io, &from->dest.addr.sa, ret);
Quoted 1 line
SH could be either file descriptor (in case of non-dco link) or handle (non-dco tun and dco link). […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 19
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 06 Feb 2025 18:46:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
to look at the new patch set (#20).
Change subject: dco-win: multipeer support
......................................................................
dco-win: multipeer support
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depending on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork to figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/ovpn_dco_win.h
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.c
11 files changed, 484 insertions(+), 132 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/15/815/20
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -284,7 +285,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -422,7 +422,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +240 -61
395 lines not on this page · raw message
src/openvpn/dco_win.h +11 -5
@@ -31,19 +31,25 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { +DCO_MODE_UNINIT , +DCO_MODE_P2P , +DCO_MODE_MP +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type ifmode; + };typedef struct dco_context dco_context_t ; -struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +void +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +4 -1
@@ -1323,7 +1323,10 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +/* we cannot end up here when using dco */ +ASSERT (!dco_enabled (&c->options)); + +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = false };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -2005,7 +2005,7 @@if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +82 -3
107 lines not on this page · raw message
src/openvpn/socket.c +119 -56
213 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1046,6 +1048,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1116,6 +1119,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
src/openvpn/tun.c +1 -1
@@ -992,7 +992,7 @@#ifdef _WIN32if (tt->backend_driver ==DRIVER_DCO ) { -dco_start_tun (tt); + tt->dco.tt = tt;return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 20
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 20: Code-Review+2
(1 comment)
File src/openvpn/socket.h:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/40fb319f_4992f85a :
PS20, Line 1130: buf_write_prepend(buf, &sa, sizeof(sa));
I *do* wonder why this is not just doing
``` buf_write_prepend(buf, &to->dest.addr.in4, sizeof(sockaddr_in); ```
... but it works as it is, and I want #815 done...
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 20
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Wed, 19 Feb 2025 21:53:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v20 1/1 dco-win: multipeer support
In reply to a message not in the archiveFrom: Lev Stipakov <[email protected]...>
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depending on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork to figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/815
This mail reflects revision 20 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -284,7 +285,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -422,7 +422,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +240 -61
395 lines not on this page · raw message
src/openvpn/dco_win.h +11 -5
@@ -31,19 +31,25 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { +DCO_MODE_UNINIT , +DCO_MODE_P2P , +DCO_MODE_MP +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type ifmode; + };typedef struct dco_context dco_context_t ; -struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +void +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +4 -1
@@ -1323,7 +1323,10 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +/* we cannot end up here when using dco */ +ASSERT (!dco_enabled (&c->options)); + +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = false };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -2005,7 +2005,7 @@if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +82 -3
107 lines not on this page · raw message
src/openvpn/socket.c +119 -56
213 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1046,6 +1048,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1116,6 +1119,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
src/openvpn/tun.c +1 -1
@@ -992,7 +992,7 @@#ifdef _WIN32if (tt->backend_driver ==DRIVER_DCO ) { -dco_start_tun (tt); + tt->dco.tt = tt;return ; }
[Openvpn-devel] [PATCH applied] Re: dco-win: multipeer support
So, finally, on v20 :-)
This has received quite a bit of stare-at-code review, and I also tested this on a windows VM with a mingw-bult openvpn.exe, using Lev's most recent DCO driver. "It works, what shall I say" ;-)
#815 on itself works, but lacks --timeout handling - so if a client disconnects (without sending EEN), kernel can not notify userland and the peer will "stick". #816 will add that functionality. Nothing will crash or misbehave in other ways, though.
NOTE: for server functionality, one needs to turn on IP forwarding on the windows system ("as usual"). For IPv4 this is a registry key + reboot, for IPv6 it's a magic netsh call (and no reboot, and after a reboot the netsh setting seems to return to "disabled"). This is all a bit ugly, so we need to see if we can make it better for the user (or at least have more documentation in our shiny new wiki).
NOTE2: on commit, uncrustify complains about ovpn_dco_win.h - which I have ignored, as this is "import an external .h file describing the API", as for the Linux file. dev-tools/special-files.list has the appropriate exclude, but the commit-hook does not know that.
Your patch has been applied to the master branch.
commit 1625d927fc79e2926015ded06a01fd8e460a4bc7
Author: Lev Stipakov Date: Wed Feb 19 22:54:17 2025 +0100
dco-win: multipeer support
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30935.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Attention is currently required from: cron2, flichtenheld, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
Patch Set 20:
(1 comment)
File src/openvpn/socket.h:
http://gerrit.openvpn.net/c/openvpn/+/815/comment/fc6cf011_d31d4dd0 :
PS20, Line 1130: buf_write_prepend(buf, &sa, sizeof(sa));
Quoted 1 line
I *do* wonder why this is not just doing […]
Right, don't know why I needed this temporary buffer. Do you want me to send v21 or shall I send a follow-up patch?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 20
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 20 Feb 2025 06:12:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2.
cron2 has uploaded a new patch set (#21) to the change originally created by stipa. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: dco-win: multipeer support
......................................................................
dco-win: multipeer support
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depending on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork to figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30935.html
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/ovpn_dco_win.h
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.c
11 files changed, 484 insertions(+), 132 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/15/815/21
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -293,7 +294,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -422,7 +422,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +240 -61
395 lines not on this page · raw message
src/openvpn/dco_win.h +11 -5
@@ -31,19 +31,25 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { +DCO_MODE_UNINIT , +DCO_MODE_P2P , +DCO_MODE_MP +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type ifmode; + };typedef struct dco_context dco_context_t ; -struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +void +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +4 -1
@@ -1323,7 +1323,10 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +/* we cannot end up here when using dco */ +ASSERT (!dco_enabled (&c->options)); + +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = false };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -2005,7 +2005,7 @@if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +82 -3
107 lines not on this page · raw message
src/openvpn/socket.c +119 -56
213 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1046,6 +1048,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1116,6 +1119,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
src/openvpn/tun.c +1 -1
@@ -992,7 +992,7 @@#ifdef _WIN32if (tt->backend_driver ==DRIVER_DCO ) { -dco_start_tun (tt); + tt->dco.tt = tt;return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 21
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2.
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/815?usp=email )
Change subject: dco-win: multipeer support
......................................................................
dco-win: multipeer support
This is the main commit for dco-win multipeer
implementation.
This adds concept of "mode" to DCO implementation, which is peer-to-peer or multipeer. Depending on mode, some functions use MP-specific IOCTL commands, which include peer-id as a part of input.
The driver initialization accomodates server mode, in which tun device is created before transport.
Since on Windows the socket is visible to the kernel only, control channel packets have to be prepended with remote sockaddr of the peer - this allows userspace to distinguish among peers. Sadly there is no reliable way to get peer local address, such as on Linux/FreeBSD, so we have to do a bit of guesswork to figure out IP address based on remote IP and local routing table, which may backfire if there are multiple IPs assigned to the same network adapter. However, as for now peer-specific local IP is not used by the driver. We use instead the result of bind() to the listening address.
Existing sockethandle_finalize() function has been refactored to accomodate packets with possibly prepended sockaddr.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30935.html
---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/ovpn_dco_win.h
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun.c
11 files changed, 484 insertions(+), 132 deletions(-)
src/openvpn/dco.h +3 -2
@@ -106,9 +106,10 @@* * @param mode the instance operating mode (P2P or multi-peer) * @param dco the context to initialize +* @param dev_node device node, used on Windows to specify certain DCO adapter * @return true on success, false otherwise */ -bool ovpn_dco_init (int mode,dco_context_t *dco); +bool ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node);/** * Open/create a DCO interface
@@ -293,7 +294,7 @@ }static inline bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {return true; }
src/openvpn/dco_freebsd.c +1 -1
@@ -165,7 +165,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {if (open_fd (dco) <0 ) {
src/openvpn/dco_linux.c +1 -1
@@ -422,7 +422,7 @@ }bool -ovpn_dco_init (int mode,dco_context_t *dco) +ovpn_dco_init (int mode,dco_context_t *dco,const char *dev_node) {switch (mode) {
src/openvpn/dco_win.c +240 -61
395 lines not on this page · raw message
src/openvpn/dco_win.h +11 -5
@@ -31,19 +31,25 @@typedef OVPN_KEY_SLOT dco_key_slot_t ;typedef OVPN_CIPHER_ALG dco_cipher_t ; +typedef enum { +DCO_MODE_UNINIT , +DCO_MODE_P2P , +DCO_MODE_MP +}dco_mode_type ; +struct dco_context {struct tuntap *tt; +dco_mode_type ifmode; + };typedef struct dco_context dco_context_t ; -struct tuntap -create_dco_handle (const char *devname,struct gc_arena *gc); +void +dco_mp_start_vpn (HANDLE handle,struct link_socket *sock);void -dco_create_socket (HANDLE handle,struct addrinfo *remoteaddr,bool bind_local, -struct addrinfo *bind,int timeout, -struct signal_info *sig_info); +dco_p2p_new_peer (HANDLE handle,struct link_socket *sock,struct signal_info *sig_info);void dco_start_tun (struct tuntap *tt);
src/openvpn/forward.c +4 -1
@@ -1323,7 +1323,10 @@ }else { -sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand }; +/* we cannot end up here when using dco */ +ASSERT (!dco_enabled (&c->options)); + +sockethandle_t sh = { .is_handle = true, .h = c->c1.tuntap->hand, .prepend_sa = false };sockethandle_finalize (sh, &c->c1.tuntap->reads, &c->c2.buf,NULL ); }#else /* ifdef _WIN32 */
src/openvpn/init.c +1 -1
@@ -2005,7 +2005,7 @@if (dco_enabled (&c->options)) { -ovpn_dco_init (c->mode, &c->c1.tuntap->dco); +ovpn_dco_init (c->mode, &c->c1.tuntap->dco, c->options.dev_node); }/* open the tun device */
src/openvpn/ovpn_dco_win.h +82 -3
107 lines not on this page · raw message
src/openvpn/socket.c +119 -56
213 lines not on this page · raw message
src/openvpn/socket.h +21 -0
@@ -224,6 +224,7 @@#define SF_HOST_RANDOMIZE (1<<3)#define SF_GETADDRINFO_DGRAM (1<<4)#define SF_DCO_WIN (1<<5) +#define SF_PREPEND_SA (1<<6)unsigned int sockflags;int mark;const char *bind_dev;
@@ -287,6 +288,7 @@HANDLE h; };bool is_handle; +bool prepend_sa;/* are incoming packets prepended with sockaddr? */ } sockethandle_t; int sockethandle_finalize(sockethandle_t sh,
@@ -1046,6 +1048,7 @@ { *from = sock->info.lsa->actual; sh.is_handle = true; + sh.prepend_sa = sock->sockflags &SF_PREPEND_SA ; }return sockethandle_finalize (sh, &sock->reads, buf, from); }
@@ -1116,6 +1119,24 @@ err =SocketHandleGetLastError (sh); } } + +/* dco-win mp requires control packets to be prepended with sockaddr */ +if (sock->sockflags &SF_PREPEND_SA ) + { +if (to->dest.addr.sa.sa_family ==AF_INET ) + { +struct sockaddr_in sa; +memcpy (&sa, &to->dest.addr.in4,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } +else + { +struct sockaddr_in6 sa; +memcpy (&sa, &to->dest.addr.in6,sizeof (sa)); +buf_write_prepend (buf, &sa,sizeof (sa)); + } + } +socket_send_queue (sock, buf, to);if (status <0 ) {
src/openvpn/tun.c +1 -1
@@ -992,7 +992,7 @@#ifdef _WIN32if (tt->backend_driver ==DRIVER_DCO ) { -dco_start_tun (tt); + tt->dco.tt = tt;return ; }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/815?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia267276d61fa1425ba205f54ba6eb89021f32dba
Gerrit-Change-Number: 815
Gerrit-PatchSet: 21
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-MessageType: merged